package util;

import java.io.BufferedReader;
import java.io.IOException;
import java.util.ArrayList;

public class Helpers {
	public int read(BufferedReader f) throws IOException {
		return Integer.parseInt(f.readLine());
	}
	
	public int[] read(BufferedReader f, int N) throws IOException {
		String[] t = f.readLine().split(" ");
		int[] a = new int[N];
		for (int i=0; i<N; i++) {
			a[i] = Integer.parseInt(t[i]);
		}
		return a;
	}
	
	public boolean isPrime(int N) {
		for (int i=2; i*i<=N; i++) {
			if (N%i == 0) return false;
		}
		return true;
	}
	
	// ------------------------------------------------------------------------
	// Another way to check prime number
	// ------------------------------------------------------------------------
	private final int MAX_CACHE = 10000;
	private ArrayList<Integer> primes;
	public void sieve(int N) {
		int M = Math.min(N, MAX_CACHE);
		boolean[] np = new boolean[M + 1];
		for (int i=2; i*i<=M; i++) {
			if (np[i]) {
				continue;
			}
			for (int j=i*2; j<=M; j+=i) {
				np[j] = true;
			}
		}
		for (int i=2; i<=M; i++) if (!np[i]) primes.add(i);
	}
	
	public boolean isPrime2(int a) {
		if (a < MAX_CACHE) return primes.contains(a);
		for (int i : primes) {
			if (a % i == 0) return false;
		}
		return true;
	}
}
